<?php
//require_once(_DOCROOT__.__COM__ ."/dialogbox/ComNoteEditPanel.class.php");

class ComNoteListPanel extends QPanel {
    // Local instance of the Meta DataGrid to list ComNotes
    public $dtgComNotes;

    // Other public QControls in this panel
    public $btnCreateNew;
    public $pxyEdit;

    //
    protected $pnlComeNoteEdit;

    // Callback Method Names
    protected $strSetEditPanelMethod;
    protected $strCloseEditPanelMethod;

    public function __construct($objParentObject, $strSetEditPanelMethod, $strCloseEditPanelMethod, $strControlId = null) {
        // Call the Parent
        try {
            parent::__construct($objParentObject, $strControlId);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }

        // Record Method Callbacks
        $this->strSetEditPanelMethod =  $strSetEditPanelMethod;
        $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;

        // Setup the Template
        $this->strTemplate = __DOCROOT__.__COM__ . '/tpl/qepanel_list.tpl.php';


        // Instantiate the Meta DataGrid
        $this->dtgComNotes = new ComNoteDataGrid($this);

        // Style the DataGrid (if desired)
        $this->dtgComNotes->CssClass = 'datagrid';
        $this->dtgComNotes->AlternateRowStyle->CssClass = 'alternate';


        
        // Add Pagination (if desired)
        $this->dtgComNotes->Paginator = new QPaginator($this->dtgComNotes);
        $this->dtgComNotes->ItemsPerPage = 8;

        $this->dtgComNotes->AdditionalConditions = QQ::Equal(QQN::ComNote()->SchoolComId, $_SESSION['ComSchoolId']) ;


        // Create the Other Columns (note that you can use strings for com_note's properties, or you
        // can traverse down QQN::com_note() to display fields that are down the hierarchy)
        $this->dtgComNotes->MetaAddColumn('Date');

        //$this->dtgComNotes->MetaAddColumn(QQN::ComNote()->SchoolCom);
        $this->dtgComNotes->MetaAddTypeColumn('Type', 'ComNoteType');
        //    $this->dtgComNotes->MetaAddColumn(QQN::ComNote()->EuserObject);
        //$this->dtgComNotes->MetaAddColumn('Attachments');
        //$this->dtgComNotes->MetaAddColumn('Notes');
        $this->dtgComNotes->AddColumn(new QDataGridColumn('Notes', '<?= $_FORM->strTruncate($_ITEM->Notes,60) ?>'));
        /*$this->dtgComNotes->AddColumn(new QDataGridColumn('Notes', '<?= $_FORM->strTruncate($_ITEM,30) ?>', 'Width=10'));
        */
        $this->dtgComNotes->AddRowAction(new QMouseOverEvent(), new QCssClassAction('selectedStyle'));
        $this->dtgComNotes->AddRowAction(new QMouseOutEvent(), new QCssClassAction());
        $this->dtgComNotes->RowActionParameterHtml = '<?= $_ITEM->Id ?>';
        $this->dtgComNotes->AddRowAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEdit_Click'));

        // Setup the Create New button
        $this->btnCreateNew = new QButton($this);
        $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('ComNote');
        $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));


    }

    public function pxyEdit_Click($strFormId, $strControlId, $strParameter) {
        $strParameterArray = explode(',', $strParameter);

        $objEditPanel = new ComNoteEditPanel( $this, 'ClosePanel', $strParameterArray[0]);
        $strMethodName = $this->strSetEditPanelMethod;
        $this->objForm->$strMethodName($objEditPanel, "pnlComNoteEdit");

    }

    public function btnCreateNew_Click($strFormId, $strControlId, $strParameter) {

        $objEditPanel = new ComNoteEditPanel( $this, 'ClosePanel');
        $strMethodName = $this->strSetEditPanelMethod;
        $this->objForm->$strMethodName($objEditPanel, "pnlComNoteEdit");
    }
}
?>